#ifndef GITUPDATER_H
#define GITUPDATER_H

#include <QObject>
#include <QProcess>
#include <QTimer>
#include <QThread>
#include <QVariantMap>

class gitUpdater : public QObject
{
    Q_OBJECT
public:
    explicit gitUpdater(QObject *parent = nullptr);
    ~gitUpdater();

    const QString appRootPath = "./master";


public slots:
    void init();
    void getCurrentVersion();
    void getLatestVersion();
    void startUpdate();

signals:
    void response(bool success, const QString &command, const QVariantMap &result);

protected slots:
    void readProcessOutput();
private slots:
    void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void handleProcessError(QProcess::ProcessError error);
    void handleReadyReadStandardOutput();
    void handleReadyReadStandardError();
    void handleTimeout();

private:
    void runCommand(const QString &program, const QStringList &arguments, int timeout);
    void parseGitDescribeOutput(const QString &output, bool isCurrent);
    void parseGitLsRemoteOutput(const QString &output);

    bool finishWthSuccessful=true;
    QProcess *process;
    QTimer *timeoutTimer;
    QString currentOperation;
    bool isCurrentVersion;
    QString lastOutput;
    QString last_version;
    QString latestTag;
};

#endif // GITUPDATER_H
